<?php
	namespace Api\Controller;
	use Think\Controller;
	header("Content-Type:text/html;charset=utf-8");
	class UserController extends Controller
	{
		/**
	     * 用户注册
	     * @param null $username 用户名
	     * @param null $email   邮箱
	     * @param null $password 密码
	     * Created by Dr.Chan<cynmsg@gmail.com>
	     */
	    	public function register($tel=null, $nickname = null, $password = null,$type = null, $code=null) 
	    	{
	    			/* $reginfo = M("User") -> where("tel = '{$_POST['tel']}'") ->find();
	    			$codeinfo = M("Vcode") -> where("tel = '{$_POST['tel']}'") -> find(); */
	    			
		           $result = M("User")->where("tel={$_POST['tel']}") ->find();
		            if ($result != null) 
		            {
		            	$array['result'] = -1;
		            	$array['message'] = "该手机号已注册！";
		            	echo json_encode($array, JSON_UNESCAPED_SLASHES);
		            	exit;
		            } 
		            /*if ($codeinfo['code'] != $code)
		            {
		            	$array['result'] = -2;
		            	$array['message'] = "验证码不正确！";
		            	$array['codeinfo'] = $codeinfo;
		            	$array['code'] = $code;
		            	echo json_encode($array, JSON_UNESCAPED_SLASHES);
		            	exit;
		            }
		            elseif ((time() - $codeinfo['sttime']) > 60)
		            {
		            	$array['result'] = -3;
		            	$array['message'] = "验证码过期！";
		            	echo json_encode($array, JSON_UNESCAPED_SLASHES);
		            	exit;
		            } */
		            M("User")->create($_POST);
		            $data['uid'] = M("User") -> add();  //注册成功返回主键
		            $data['logintime'] = date('Y-m-d H:i:s',time());
		            
		            $array['uid'] = $data['uid'];
	        		$array['logintime'] = $data['logintime'];
	        		$prep_code = serialize($array);
	        		$block = mcrypt_get_block_size('des', 'ecb');
	        		if (($pad = $block - (strlen($prep_code) % $block)) < $block) {
	        			$prep_code .= str_repeat(chr($pad), $pad);
	        		}
	        		$encrypt = mcrypt_encrypt(MCRYPT_DES, ENCODE_KEY, $prep_code, MCRYPT_MODE_ECB);
	        		$token = base64_encode($encrypt);
	        		M("User") -> where('uid='.$array['uid']) -> setField('token', $token); //创建token
					
	        		$data = array(
	        				'uid'=>$array['uid'],
	        				'nickname'=>$nickname,
	        				'tel'=>$tel,
	        				'type'=>$type,
	        				'token'=>$token
	        		);
	        		
		            $array1['result'] = "0";
		            $array1['message'] = "注册成功";
		            $array1['userinfo'] = $data;
		            echo json_encode($array1, JSON_UNESCAPED_SLASHES);
		            exit;
	         	} 	   
	    	 /**
	    	  * 用户登录
	    	  * 
	    	  * @param null $tel  手机号
	    	  * @param null $password 密码
	    	  * Created by Dr.Chan<cynmsg@gmail.com>
	    	  */
			public function login($tel=null,  $password = null, $latitude = null, $longitude=null) 
	    	{
		            $result = M("User")->where("tel='{$_POST['tel']}'") ->find();
		            if ($result == null) 
		            {
		            	$array['result'] = -1;
		            	$array['message'] = "该手机号未注册！";
		            	echo json_encode($array, JSON_UNESCAPED_SLASHES);
		            	exit;
		            }
		            else
		           {
		            	$userinfo = M("User") -> where("tel='{$_POST['tel']}' and password='{$_POST['password']}'")->find();
		            	if ($userinfo == null) 
		            	{
		            		$array['result'] = -2;
		            		$array['message'] = "密码错误！";
		            		echo json_encode($array, JSON_UNESCAPED_SLASHES);
		            		exit;
		            	}
		            	else
		            	{
		            		$data['logintime'] = date('Y-m-d H:i:s',time());
		            		
		            		$array['uid'] = $userinfo['uid'];
		            		$array['logintime'] = $data['logintime'];
		            		$prep_code = serialize($array);
		            		$block = mcrypt_get_block_size('des', 'ecb');
		            		if (($pad = $block - (strlen($prep_code) % $block)) < $block) {
		            			$prep_code .= str_repeat(chr($pad), $pad);
		            		}
		            		$encrypt = mcrypt_encrypt(MCRYPT_DES, ENCODE_KEY, $prep_code, MCRYPT_MODE_ECB);
		            		$token = base64_encode($encrypt);
		            		
		            		M("User") -> where('uid='.$array['uid']) -> setField('token', $token); //创建token
		            		//经度
		            		$data1["longitude"] = $longitude;
		            		//纬度
		            		$data1["latitude"] = $latitude;
		            		//更新经纬度
		            		$where["tel"] = $tel;
		            		M("User") -> where($where) -> data($data1) ->save();
		            		
		            		$userinfo1 = M("User") -> where("tel = {$tel}") -> find();
		            		if ($userinfo1["type"] == 0) 
		            		{
		            			//用户未个人
		            			if ($userinfo1['rmtype'] != null)
		            			{
		            				$userdetailinfo = M("Userinfo") -> where("uid={$userinfo1['uid']}") -> find();
		            			}else{
		            				$userinfo1['headimg'] = "";
		            			}
		            			$userinfo1['headimg'] = $userdetailinfo['headimg'];
		            			
		            		}
		            		else
		            		{
		            			//企业用户
		            			if ($userinfo1['rmtype'] != null)
		            			{
		            				$userdetailinfo = M("Company") -> where("uid={$userinfo1['uid']}") -> find();
		            			}else{
		            				$userinfo1['headimg'] = "";
		            			}
		            			$userinfo1['headimg'] = $userdetailinfo['cplogo'];
		            		}
		            		
		            		$data2 = array(
		            				"nickname"=> $userinfo1["nickname"],
		            				"headimg"=> $userinfo1["headimg"],
		            				"uid" => $userinfo1["uid"],
		            				"type"=> $userinfo1["type"],
		            				"token"=> $userinfo1["token"],
		            				"balance"=> $userinfo1["balance"],
		            				"credit"=> $userinfo1["credit"],
		            				"dtttype"=> $userinfo1["dtttype"],
		            				"gradeid"=> $userinfo1["gradeid"],
		            				"tel"=> $userinfo1["tel"]
		            		);
		            		
		            		$array1['result'] = 0;
		            		$array1['message'] = "登录成功！";
 		            		$array1['userinfo'] = $data2;
		            		echo json_encode($array1, JSON_UNESCAPED_SLASHES);
		            		exit;
		            	}
		            } 
	         	}
	         	/**
	         	 * 用户登录验证码
	         	 *
	         	 * @param null $tel  手机号
	         	 * @param null $password 密码
	         	 * Created by Dr.Chan<cynmsg@gmail.com>
	         	 */
	         	public function verify($tel=null, $type=null)
	         	{
	         		if ($type == 0) 
	         		{
	         			//type=0用户注册
	         			$result = M("User") -> where("tel={$tel}") ->find();
	         			if ($result != null) 
	         			{
	         				$array['result'] = -1;
	         				$array['message'] = "该手机号已注册！";
	         				echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         				exit;
	         			}
	         		}
	         		else
	         		{
	         			$result = M("User") -> where("tel={$tel}") ->find();
	         			if ($result == null)
	         			{
	         				$array['result'] = -2;
	         				$array['message'] = "该手机号未注册！";
	         				echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         				exit;
	         			}
	         		}
	         		
	         		$flag = 0; 
					$post_data='';//要post的数据 
					$verify = rand(100000, 999999);//获取随机验证码		
				
					//以下信息自己填以下
					$tel = $_POST['tel'];//手机号
					
					function Post($data, $target) {
						$url_info = parse_url($target);
						$httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
						$httpheader .= "Host:" . $url_info['host'] . "\r\n";
						$httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n";
						$httpheader .= "Content-Length:" . strlen($data) . "\r\n";
						$httpheader .= "Connection:close\r\n\r\n";
						//$httpheader .= "Connection:Keep-Alive\r\n\r\n";
						$httpheader .= $data;
							
						$fd = fsockopen($url_info['host'], 80);
						fwrite($fd, $httpheader);
						$gets = "";
						while(!feof($fd)) {
							$gets .= fread($fd, 128);
						}
						fclose($fd);
						return $gets;
					}
					
// 					$argv = array( 
// 						'name'=>'18638784679',     //必填参数。用户账号
// 						'pwd'=>'8E81BDC879061D34C88EC7CF7E73',     //必填参数。（web平台：基本资料中的接口密码）
// 						'content'=>'验证码：'.$verify.'，请勿将验证码提供给他人。',   //必填参数。发送内容（1-500 个汉字）UTF-8编码
// 						'mobile'=>$tel,   //必填参数。手机号码。多个以英文逗号隔开
// 						'stime'=>'',   //可选参数。发送时间，填写时已填写的时间发送，不填时为当前时间发送
// 						'sign'=>'爱上秀',  //必填参数。用户签名。
// 						'type'=>'pt',  //必填参数。固定值 pt
// 						'extno'=>''    //可选参数，扩展码，用户定义扩展码，只能为数字
// 					); 
// 					//print_r($argv);exit;
// 					//构造要post的字符串 
// 					//echo $argv['content'];
// 					foreach ($argv as $key=>$value) { 
// 						if ($flag!=0) { 
// 							$params .= "&"; 
// 							$flag = 1; 
// 						} 
// 						$params.= $key."="; $params.= urlencode($value);// urlencode($value); 
// 						$flag = 1; 
// 					} 
// 					$url = "http://web.cr6868.com/asmx/smsservice.aspx?".$params; //提交的url地址
// 					$con= substr( file_get_contents($url), 0, 1);  //获取信息发送后的状态

					$target = "http://api.chanzor.com/send";
					
					$argv = array(
							"account" => "989b71",
							"password" => "D1E9030F74EF4F5C5CDBCB0867E35D51",
							"mobile" => $tel,
							"content" => "您的短信验证码是".$verify."。如非本人操作，请忽略此短信。本短信免费。【爱上秀】"
					);
					
					foreach ($argv as $key=>$value) {
						if ($flag!=0) {
							$post_data .= "&";
							$flag = 1;
						}
						$post_data.= $key."="."'$value'";// urlencode($value);
						$flag = 1;
					}
					
					$gets = Post($post_data, $target);
					
					$result = json_decode(substr($gets, 161));
					function object_array($array)
					{
						if(is_object($array))
						{
							$array = (array)$array;
						}
						if(is_array($array))
						{
							foreach($array as $key=>$value)
							{
								$array[$key] = object_array($value);
							}
						}
						return $array;
					}
					
					$arr = object_array($result);
					//var_dump($arr);
					//请自己解析$gets字符串并实现自己的逻辑
					//<State>0</State>表示成功,其它的参考文档
					
					
					
					
					if($arr["status"] == 0){
						//yecw add start 20150821
						//校验码验证
						$data['tel'] = $_REQUEST ['tel'];
						$data['code'] = $verify;
						$data['sttime'] = time();
						$result = M("Vcode") ->where("tel='{$_REQUEST ['tel']}'") -> find();
						
						if ($result != null) 
						{
							$res = M("Vcode") ->where("tel='{$_REQUEST ['tel']}'") -> delete();
						}	
						$res = M("Vcode") -> data($data) -> add();
						$result = array('result'=>0,'message'=>'发送成功','data'=>$data['code']);
						echo json_encode($result);
						die();
					}else{
						//echo "<script>alert('发送失败!');history.back();</script>";
						$result = array('result'=>-1,'message'=>'发送失败','data'=>'');
						echo json_encode($result);
						die();
					}
	         	}
	         	/**
	         	 * 忘记密码
	         	 *
	         	 * @param null $tel  手机号
	         	 * @param null $password 密码
	         	 * Created by Dr.Chan<cynmsg@gmail.com>
	         	 */
	         	public function forgetpwd($tel=null, $code=null, $password=null)
	         	{
	         		$result = M("User")->where("tel='{$_POST['tel']}'") ->find();
	         		$codeinfo = M("Vcode") -> where("tel = '{$_POST['tel']}'") -> find(); 
	         		if ($result == null)
	         		{
	         			$array['result'] = -2;
	         			$array['message'] = "该手机号未注册！";
	         			echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         			exit;
	         		}
	         		if ($codeinfo['code'] != $code)
	         		{
	         			$array['result'] = -3;
	         			$array['message'] = "验证码不正确！";
	         			echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         			exit;
	         		}
	         		elseif ((time() - $codeinfo['sttime']) > 60)
	         		{
	         			$array['result'] = -4;
	         			$array['message'] = "验证码过期！";
	         			echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         			exit;
	         		}
	         		$data['password'] = $password;
	         		$result = M("User") -> where("uid = {$result['uid']}") ->save($data);
	         		
	         		if ($result > 0) 
	         		{
	         			$array['result'] = 0;
	         			$array['message'] = "密码修改成功！";
	         			echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         			exit;
	         		}
	         		else
	         		{
	         			$array['result'] = -1;
	         			$array['message'] = "密码修改失败！";
	         			echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         			exit;
	         		}
	         	}
	         	/**
	         	 * 修改密码
	         	 *
	         	 * @param null $tel  手机号
	         	 * @param null $password 密码
	         	 * Created by Dr.Chan<cynmsg@gmail.com>
	         	 */
	         	public function modifypwd($uid=null, $token=null, $oldpassword=null, $newpassword=null)
	         	{
	         		$userinfo = M("User") -> where("uid = {$_POST['uid']}") ->find();
	         		/* if ($userinfo['token'] != $_POST['token'])
	         		{
	         			$array['result'] = -2;
	         			$array['message'] = "token过期或错误，请重新登录获取";
	         			echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         			exit;
	         		} */
	         		$result = M("User") -> where("uid='{$_POST['uid']}' and password='{$_POST['oldpassword']}'") -> find();
	         		if ($result == null) 
	         		{
	         			$array['result'] = -1;
	         			$array['message'] = "原密码填写错误！";
	         			echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         			exit;
	         		}
	         		else
	         		{
	         			$data['password'] = $_POST['newpassword'];
	         			$res = M("User") -> where("uid = {$_POST['uid']}") ->save($data);
	         			if ($res > 0) 
	         			{
	         				$array['result'] = 0;
	         				$array['message'] = "用户密码修改成功！";
	         				echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         				exit;
	         			}
	         			else
	         			{
	         				$array['result'] = -3;
	         				$array['message'] = "对不起，系统发生错误，用户密码修改失败！";
	         				echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         				exit;
	         			}
	         		}
	         	}
	         	/**
	         	 * 修改手机号
	         	 *
	         	 * @param null $tel  手机号
	         	 * @param null $password 密码
	         	 * Created by Dr.Chan<cynmsg@gmail.com>
	         	 */
	         	public function modtel($token=null, $oldtel=null, $newtel=null, $code=null)
	         	{
	         		$result = M("User") -> where("tel='{$_POST['newtel']}'") ->find();
	         		if ($result != null)
	         		{
	         			$array['result'] = -5;
	         			$array['message'] = "新手机号已注册！";
	         			echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         			exit;
	         		}
	         		$codeinfo = M("Vcode") -> where("tel = '{$_POST['oldtel']}'") -> find();
	         		$userinfo = M("User") -> where("tel = {$_POST['oldtel']}") ->find();
	         		if ($userinfo['token'] != $_POST['token'])
	         		{
	         			$array['result'] = -2;
	         			$array['message'] = "token过期或错误，请重新登录获取";
	         			echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         			exit;
	         		}
	         		/* if ($codeinfo['code'] != $code)
	         		{
	         			$array['result'] = -3;
	         			$array['message'] = "验证码不正确！";
	         			echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         			exit;
	         		}
	         		elseif ((time() - $codeinfo['sttime']) > 60)
	         		{
	         			$array['result'] = -4;
	         			$array['message'] = "验证码过期！";
	         			echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         			exit;
	         		} */
	         		$data['tel'] = $_POST['newtel'];
	         		$result = M("User") -> where("uid = {$userinfo['uid']}") ->save($data);
	         		if ($result > 0) 
	         		{
	         			$array['result'] = 0;
	         			$array['message'] = "修改手机号成功！";
	         			echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         			exit;
	         		}
	         		else
	         		{
	         			$array['result'] = -1;
	         			$array['message'] = "由于系统原因，修改手机号失败！";
	         			echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         			exit;
	         		}
	         	}
	         	/**
	         	 * 上传个人资料
	         	 *
	         	 * @param null $tel  手机号
	         	 * @param null $password 密码
	         	 * Created by Dr.Chan<cynmsg@gmail.com>
	         	 */
	         	public function uploadUserInfo($uid=null, $token=null)
	         	{
	         		$userinfo = M("User") -> where("uid = {$uid}") ->find();
	         		/* if ($userinfo['token'] != $_POST['token'])
	         		{
		         		$array['result'] = -2;
		         		$array['message'] = "token过期或错误，请重新登录获取";
		         		echo json_encode($array, JSON_UNESCAPED_SLASHES);
		         		exit;
	         		} */
	         		
	         		$data['nickname'] = $_POST['nickname'];
	         		$res = M('User') -> where("uid={$uid}") -> setField($data); 
	         		unset($_POST['nickname']);
	         		//var_dump($res);
	         		if ($res >= 0) 
	         		{
	         		
	         			$data1['content'] = $_POST['motto'];
	         			if ($data1 != null) 
	         			{
	         				$mottoid = M("Motto") -> data($data1) -> add();
	         				unset($_POST['motto']);
	         				$_POST['mottoid'] = $mottoid;
	         			} 
	         			
						$arr = I('post.');
						
						//上传个人资料
						if ($userinfo['type'] == 0) 
						{
							$result = M("Userinfo") -> where("uid={$uid}") -> find();
							if ($result >0 ) 
	 						{
								$result = M("Userinfo") -> where("uid={$uid}") -> setField($arr);
	 						}
							else
							{	
								
								$result = M("Userinfo") -> add($arr);
							}
							/* var_dump($result1); */
							if ($result != null) 
							{
								$array['result'] = 0;
								$array['message'] = "个人资料上传成功";
								echo json_encode($array, JSON_UNESCAPED_SLASHES);
								exit;
							}
							else
							{
								$array['result'] = -1;
								$array['message'] = "个人资料上传失败";
								echo json_encode($array, JSON_UNESCAPED_SLASHES);
								exit;
							} 
						}
						else
						{
							$result = M("Company") -> where("uid={$uid}") -> find();
							if ($result >0 )
							{
								$result = M("Company") -> where("uid={$uid}") -> setField($arr);
							}
							else 
							{
								$result = M("Company") -> add($arr);
							}
						}
						if ($result > 0) 
						{
							$array['result'] = 0;
							$array['message'] = "公司资料上传成功";
							echo json_encode($array, JSON_UNESCAPED_SLASHES);
							exit;
						}
						else
						{
							$array['result'] = -3;
							$array['message'] = "公司资料上传失败";
							echo json_encode($array, JSON_UNESCAPED_SLASHES);
							exit;
						}
	         		}	         		
	         	}
	         	/**
	         	 * 个人完善资料
	         	 *
	         	 *	token字段值
	         	 *	sex 性别
	         	 * @param null $uid  用户id
	         	 * @param null $password 密码
	         	 * Created by Dr.Chan<cynmsg@gmail.com>
	         	 */
	         	public function improveuserinfo($uid=null, $token=null, $tagname=null)
	         	{
	         		
	         		$userinfo = M("User") -> where("uid = {$_POST['uid']}") ->find();
	         		/* if ($userinfo['token'] != $_POST['token'])
	         		 {
		         		$array['result'] = -2;
		         		$array['message'] = "token过期或错误，请重新登录获取";
		         		echo json_encode($array, JSON_UNESCAPED_SLASHES);
		         		exit;
	         		} */ 
	         		$arr = I("post.");
	         		//上传个人资料
	         		if ($userinfo['type'] == 0)
	         		{
	         			$result = M("Userinfo") -> where("uid={$uid}") -> find();
	         			if ($result >0 )
	         			{
	         				$result = M("Userinfo") -> where("uid={$uid}") -> setField($arr);
	         			}
	         			else
	         			{
	         				$result = M("Userinfo") -> add($arr);
	         			}
	         			if ($result != null)
	         			{
	         				$array['result'] = 0;
	         				$array['message'] = "个人资料上传成功！";
	         				$array['post'] = $_POST;
	         				/* $array['tagid'] = $tagid;
	         				$array['spreadid'] = $_POST['spreadid']; */
	         				echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         				exit;
	         			}
	         			else
	         			{
	         				$array['result'] = -1;
	         				$array['message'] = "个人资料上传失败！";
	         				echo json_encode($array, JSON_UNESCAPED_SLASHES);
	         				exit;
	         			}
	         		}
	         		else
	         		{
		         		$result = M("Company") -> where("uid={$uid}") -> find();
		         		if ($result >0 )
		         		{
		         			$result = M("Company") -> where("uid={$uid}") -> setField($arr);
		         		}
		         		else
		         		{
		         			$result = M("Company") -> add($arr);
		         		}
		         		if ($result > 0)
		         		{
		         			$array['result'] = 0;
		         			$array['message'] = "公司资料上传成功！";
		         			echo json_encode($array, JSON_UNESCAPED_SLASHES);
		         			exit;
		         		}
		         		else
		         		{
		         			$array['result'] = -3;
		         			$array['message'] = "公司资料上传失败！";
		         			echo json_encode($array, JSON_UNESCAPED_SLASHES);
		         			exit;
		         		}
		         	}
	         	}

	         	/*
	         	 *个人主页信息
	         	 *
	         	 *
	         	 */
	         	public function userHomepage($uid=null, $uids=null)
	         	{
// 	         		if ($this->checkedToken($uid,$token)) 
// 	         		{
						if ($uids == null) 
						{
							$where["uid"] = $uid;
							
						}
						else
						{
							//查看自己的界面
							$where["uid"] = $uids;
							M("User") -> where($where) ->setInc("seetimes", 1);
						}
						
	         			
	         			$userinfo = M("User") -> field("uid,nickname,type,rmtype") -> where($where) -> find();
	         			//var_dump($userinfo);
	         			if ($uids == null)
	         			{
	         				$mutul = "3";
	         			}
	         			else
	         			{
	         				$condition1["uid"] = $uid;
	         				
	         				$attentionInfo = M("User") -> where($condition1) -> getField("attention");
	         				if ($uids != null) 
	         				{
	         					$condition2["uid"] = $uids;
	         					$otherInfo = M("User") -> where($condition2) ->getField("attention");
	         				}
	         				
	         				if ($attentionInfo == null)
	         				{
	         					$mutul = "0";
	         				}
	         				else
	         				{
	         					$attentionArray = explode(",", $attentionInfo);
	         					if ($otherInfo == null) 
	         					{
	         						$otherInfo = array();
	         					}
	         					else
	         					{
	         						$otherInfo = explode(",", $otherInfo);
	         					}
	         					if (in_array($uids, $attentionArray) && in_array($uid, $otherInfo))
	         					{
	         						$mutul = "2";//uid和uids已互相关注
	         					}
	         					elseif (in_array($uids, $attentionArray))
	         					{
	         						$mutul = "1";//已关注过要查看的这个人的uid
	         					}
	         					else
	         					{
	         						$mutul = "0";//未关注过要查看的这个人的id
	         					}
	         				}
	         			}
	         			
	         			if ($userinfo["type"] == 0) 
	         			{
	         				//个人主页
	         				
		         			if ($userinfo["rmtype"] == 1) 
		         			{
		         				if ($uids == null) 
		         				{
		         					$where1["think_user.uid"] = $uid;
		         				}
		         				else
		         				{
		         					$where1["think_user.uid"] = $uids;
		         				}
		         				
		         				$userinfo1 = M("User") -> join("__USERINFO__ on __USER__.uid=__USERINFO__.uid") -> field("think_user.uid,nickname,dtttype,attention,age,sex,height,weight,sanwei,headimg,tagname,mottoid,background,position,school") -> where($where1) -> order("dtttype desc") -> find();
		         				
		         				if ($userinfo1["attention"] != null) 
		         				{	
			         				//查看关注数
			         				$auids = explode(",", $userinfo1["attention"]);
			         				$count = count($auids);
		         				}
		         				else
		         				{
		         					$count = 0;
		         				}
		         				//查看被关注数(粉丝数)
		         				if ($uids == null) 
		         				{
			         				$condition["attention"] = array(
			         						array("like","$uid,%"),
			         						array("like","%,$uid"),
			         						array("like","%,$uid,%"),
			         						array("like",$uid),
			         						'ThinkPHP','OR'
			         				);
		         				}
		         				else
		         				{
		         					$condition["attention"] = array(
		         							array("like","$uids,%"),
		         							array("like","%,$uids"),
		         							array("like","%,$uids,%"),
		         							array("like",$uids),
		         							'ThinkPHP','OR'
		         					);
		         				}
		         				
		         				$uids1 = M("User") -> field("uid") -> where($condition) -> select();
		         				
		         				if ($uids1 != null) 
		         				{
			         				foreach ($uids1 as $k => $v)
			         				{
			         					$uids2[$k] = $v["uid"]; 
			         				}
			         				$count1 = count($uids2);
		         				}
		         				else
		         				{
		         					$count1 = 0;
		         				}
		         				//var_dump($count1);
		         				//艺人标签
		         				if ($userinfo1['tagname'] != null) 
		         				{
			         				$tagname = explode("-", $userinfo1['tagname']);
			         				unset($userinfo1['tagname']);
			         				$userinfo1["tagname"] = $tagname;
		         				}
		         				else
		         				{
		         					$userinfo1["tagname"] = array();
		         				}
		         				//查询人生格言
		         				if ($userinfo1["mottoid"] == null) 
		         				{
		         					unset($userinfo1["mottoid"]);
		         					$userinfo1["motto"] = "";
		         				}
		         				else
		         				{
		         					$where2["mottoid"] = $userinfo1["mottoid"];
		         					$motto = M("Motto") -> where($where2) -> getField('content');
		         					unset($userinfo1["mottoid"]);
		         					$userinfo1["motto"] = $motto;
		         				}
		         				//var_dump($motto);
		         				
		         				if ($userinfo1["age"] == null)
		         				{
		         					unset($userinfo1['age']);
		         					$userinfo1["age"] = "";
		         				}
		         				if ($userinfo1["height"] == null)
		         				{
		         					unset($userinfo1['height']);
		         					$userinfo1["height"] = "";
		         				}
		         				if ($userinfo1["weight"] == null)
		         				{
		         					unset($userinfo1['weight']);
		         					$userinfo1["weight"] = "";
		         				}
		         				if ($userinfo1["sanwei"] == null)
		         				{
		         					unset($userinfo1['sanwei']);
		         					$userinfo1["sanwei"] = "";
		         				}
		         				if ($userinfo1["headimg"] == null)
		         				{
		         					unset($userinfo1['headimg']);
		         					$userinfo1["headimg"] = "";
		         				}
		         				if ($userinfo1["position"] == null) 
		         				{
		         					$userinfo1["position"] = "";
		         				}
		         				else
		         				{
		         					$position = explode("-", $userinfo1["position"]);
		         					unset($userinfo1["position"]);
		         					$userinfo1["position"] = $position[1];
		         				}
		         				if ($userinfo1["school"] == null) 
		         				{
		         					unset($userinfo1['school']);
		         					$userinfo1["school"] = "";
		         				}
		         				if ($userinfo1["background"] == null) 
		         				{
		         					unset($userinfo1["background"]);
		         					$userinfo1["background"] = "";
		         				}
		         				
		         				$data = array(
		         						"uid"=> $userinfo1["uid"],
		         						"nickname" => $userinfo1['nickname'],
		         						"background"=>$userinfo1["background"],
		         						"dtttype" =>$userinfo1["dtttype"],
		         						"sex" => $userinfo1["sex"],
		         						"headimg" => $userinfo1["headimg"],
		         						"fans" => $count1,
		         						"attention" => $count,
		         						"tagname" => $userinfo1["tagname"],
		         						"motto" => $userinfo1["motto"],
		         						"age" => $userinfo1["age"],
		         						"height" => $userinfo1["height"],
		         						"weight" => $userinfo1["weight"],
		         						"sanwei"=> $userinfo1["sanwei"],
		         						"position"=> $userinfo1["position"],
		         						"mutual"=> $mutul,
		         						"school" => $userinfo1["school"]
		         						
		         				);
		         				//var_dump($data);
		         				if ($userinfo1 != null)
		         				{
		         					$array1['result'] = 0;
		         					$array1['message'] = "个人主页获取资料成功";
		         					$array1['userhomepage'] = $data;
		         					echo json_encode($array1, JSON_UNESCAPED_SLASHES);
		         					exit;
		         				}
		         				else
		         				{
		         					$array1['result'] = 10322;
		         					$array1['message'] = "个人主页获取资料失败";
		         					echo json_encode($array1, JSON_UNESCAPED_SLASHES);
		         					exit;
		         				}
		         			}
		         			else
		         			{
		         				if ($uids == null) 
		         				{
		         					$where3["uid"] = $uid;
		         				}
		         				else
		         				{
		         					$where3["uid"] = $uids;
		         				}
		         				
		         				$userinfo2 = M("User") -> field("uid,nickname,rmtype,dtttype,attention") -> where($where3) -> order("regtime desc") -> find();
		         				
		         				if ($userinfo2["attention"] != null)
		         				{
		         					//查看关注数
		         					$auids = explode(",", $userinfo2["attention"]);
		         					$count = count($auids);
		         				}
		         				else
		         				{
		         					$count = 0;
		         				}
		         				//查看粉丝数
		         				if ($uids == null) 
		         				{
			         				$condition["attention"] = array(
			         						array("like","$uid,%"),
			         						array("like","%,$uid"),
			         						array("like","%,$uid,%"),
			         						array("like",$uid),
			         						'ThinkPHP','OR'
			         				);
		         				}
		         				else
		         				{
		         					$condition["attention"] = array(
		         							array("like","$uids,%"),
		         							array("like","%,$uids"),
		         							array("like","%,$uids,%"),
		         							array("like",$uids),
		         							'ThinkPHP','OR'
		         					);
		         				}
		         				
		         				$uids1 = M("User") -> field("uid") -> where($condition) -> select();
		         				
		         				if ($uids1 != null)
		         				{
		         					foreach ($uids1 as $k => $v)
		         					{
		         						$uids2[$k] = $v["uid"];
		         					}
		         					$count1 = count($uids2);
		         				}
		         				else
		         				{
		         					$count1 = 0;
		         				}
		         				
		         				
		         				$data1 = array(
		         						"uid"=>$userinfo2["uid"],
		         						"nickname" => $userinfo2['nickname'],
		         						"dtttype" => $userinfo2['dtttype'],
		         						"background"=>"",
		         						"sex" => "",
		         						"headimg" => "",
		         						"fans" => $count1,
		         						"attention" => $count,
		         						"tagname" => array(),
		         						"motto" => "",
		         						"age" => "",
		         						"height" => "",
		         						"weight" => "",
		         						"sanwei"=> "",
		         						"postion"=>"",
		         						"mutual"=> $mutul,
		         						"school" => ""
		         				
		         				);
		         				//var_dump($data1);
		         				if ($userinfo2 != null)
		         				{
		         					$array1['result'] = 0;
		         					$array1['message'] = "个人主页获取资料成功";
		         					$array1['userhomepage'] = $data1;
		         					echo json_encode($array1, JSON_UNESCAPED_SLASHES);
		         					exit;
		         				}
		         				else
		         				{
		         					$array1['result'] = 10323;
		         					$array1['message'] = "个人主页获取资料失败";
		         					echo json_encode($array1, JSON_UNESCAPED_SLASHES);
		         					exit;
		         				}
		         			}
	         			}
	         			else
	         			{
	         				//公司主页
	         				if ($userinfo["rmtype"] == 1) 
	         				{
	         					//公司资料已完善
	         					if ($uids == null) 
	         					{
	         						$where1["think_user.uid"] = $uid;
	         					}
	         					else
	         					{
	         						$where1["think_user.uid"] = $uids;
	         					}
	         					
	         					$userinfo1 = M("User") -> join("__COMPANY__ on __USER__.uid=__COMPANY__.uid") -> field("think_user.uid,nickname,dtttype,attention,cplogo,tagname,address,content,linkman,phone") -> where($where1) -> order("dtttype desc,regtime desc") -> find(); 
	         					
	         					if ($userinfo1["attention"] != null)
	         					{
	         						//查看关注数
	         						$auids = explode(",", $userinfo1["attention"]);
	         						$count = count($auids);
	         					}
	         					else
	         					{
	         						$count = 0;
	         					}
	         					//查看被关注数(粉丝数)
	         					if ($uids == null) 
		         				{
			         				$condition["attention"] = array(
			         						array("like","$uid,%"),
			         						array("like","%,$uid"),
			         						array("like","%,$uid,%"),
			         						array("like",$uid),
			         						'ThinkPHP','OR'
			         				);
		         				}
		         				else
		         				{
		         					$condition["attention"] = array(
		         							array("like","$uids,%"),
		         							array("like","%,$uids"),
		         							array("like","%,$uids,%"),
		         							array("like",$uids),
		         							'ThinkPHP','OR'
		         					);
		         				}
	         					 
	         					$uids1 = M("User") -> field("uid") -> where($condition) -> select();
	         					 
	         					if ($uids1 != null)
	         					{
	         						foreach ($uids1 as $k => $v)
	         						{
	         							$uids2[$k] = $v["uid"];
	         						}
	         						$count1 = count($uids2);
	         					}
	         					else
	         					{
	         						$count1 = 0;
	         					}
	         					//企业标签
	         					
	         					if ($userinfo1["address"] == null)
	         					{
	         						unset($userinfo1['address']);
	         						$userinfo1["address"] = "";
	         					}
	         					if ($userinfo1["cplogo"] == null)
	         					{
	         						unset($userinfo1['cplogo']);
	         						$userinfo1["cplogo"] = "";
	         					}
	         					if ($userinfo1["email"] == null)
	         					{
	         						unset($userinfo1['email']);
	         						$userinfo1["email"] = "";
	         					}
	         					if ($userinfo1["background"] == null)
	         					{
	         						unset($userinfo1['background']);
	         						$userinfo1["background"] = "";
	         					}
	         					if ($userinfo1["phone"] == null)
	         					{
	         						unset($userinfo1['phone']);
	         						$userinfo1["phone"] = "";
	         					}
	         					if ($userinfo1["content"] == null)
	         					{
	         						unset($userinfo1['content']);
	         						$userinfo1["content"] = "";
	         					}
	         					
	         					$data = array(
	         							"uid"=>$userinfo1["uid"],
	         							"nickname" => $userinfo1['nickname'],
	         							"dtttype" =>$userinfo1["dtttype"],
	         							"cplogo" => $userinfo1["cplogo"],
	         							"fans" => $count1,
	         							"attention" => $count,
	         							"content" => $userinfo1["content"],
	         							"background" => $userinfo1["background"],
	         							"phone" => $userinfo1["phone"],
	         							"QQ" => $userinfo1["email"],
	         							"mutual"=> $mutul,
	         							"address" => $userinfo1["address"]
	         							 
	         					);
	         					//var_dump($data);
	         					if ($userinfo1 != null)
	         					{
	         						$array1['result'] = 0;
	         						$array1['message'] = "公司主页获取资料成功";
	         						$array1['companyhomepage'] = $data;
	         						echo json_encode($array1, JSON_UNESCAPED_SLASHES);
	         						exit;
	         					}
	         					else
	         					{
	         						$array1['result'] = 10324;
	         						$array1['message'] = "公司主页获取资料失败";
	         						echo json_encode($array1, JSON_UNESCAPED_SLASHES);
	         						exit;
	         					}
	         				}
	         				else
	         				{
	         					if ($uids == null) 
	         					{
	         						$where3["uid"] = $uid;
	         					}
	         					else
	         					{
	         						$where3["uid"] = $uids;
	         					}
	         					
	         					$userinfo2 = M("User") -> field("uid,nickname,rmtype,dtttype,attention") -> where($where3) -> order("regtime desc") -> find();
	         					 
	         					if ($userinfo2["attention"] != null)
	         					{
	         						//查看关注数
	         						$auids = explode(",", $userinfo2["attention"]);
	         						$count = count($auids);
	         					}
	         					else
	         					{
	         						$count = 0;
	         					}
	         					//查看粉丝数
	         					if ($uids == null) 
		         				{
			         				$condition["attention"] = array(
			         						array("like","$uid,%"),
			         						array("like","%,$uid"),
			         						array("like","%,$uid,%"),
			         						array("like",$uid),
			         						'ThinkPHP','OR'
			         				);
		         				}
		         				else
		         				{
		         					$condition["attention"] = array(
		         							array("like","$uids,%"),
		         							array("like","%,$uids"),
		         							array("like","%,$uids,%"),
		         							array("like",$uids),
		         							'ThinkPHP','OR'
		         					);
		         				}
	         					 
	         					$uids1 = M("User") -> field("uid") -> where($condition) -> select();
	         					 
	         					if ($uids1 != null)
	         					{
	         						foreach ($uids1 as $k => $v)
	         						{
	         							$uids2[$k] = $v["uid"];
	         						}
	         						$count1 = count($uids2);
	         					}
	         					else
	         					{
	         						$count1 = 0;
	         					}
	         					 
	         					$data1 = array(
	         							"uid"=>$userinfo2["uid"],
	         							"nickname" => $userinfo2['nickname'],
	         							"dtttype" =>$userinfo2["dtttype"],
	         							"cplogo" => "",
	         							"fans" => $count1,
	         							"attention" => $count,
	         							"content" => "",
	         							"background" => "",
	         							"phone" => "",
	         							"email" => "",
	         							"mutual"=> $mutul,
	         							"address" => ""
		      
	         					);
	         					//var_dump($data1);
	         					if ($userinfo2 != null)
	         					{
	         						$array1['result'] = 0;
	         						$array1['message'] = "公司主页获取资料成功";
	         						$array1['companyhomepage'] = $data1;
	         						echo json_encode($array1, JSON_UNESCAPED_SLASHES);
	         						exit;
	         					}
	         					else
	         					{
	         						$array1['result'] = 10325;
	         						$array1['message'] = "公司主页获取资料失败";
	         						echo json_encode($array1, JSON_UNESCAPED_SLASHES);
	         						exit;
	         					}
	         				}
	         			}
// 	         		}
// 	         		else
// 	         		{
// 	         			$array1['result'] = 10310;
// 	         			$array1['message'] = "获取信息失败";
// 	         			echo json_encode($array1, JSON_UNESCAPED_SLASHES);
// 	         			exit;
// 	         		}	
	         	}
	         	
				/*
				 *验证token的方法 
				 *   
				 */
				protected function checkedToken($uid = null,$token = null)
				{
					if ($uid==null || $token==null) 
					{
						return false;
					}
					else
					{
						$where["uid"] = $uid;
						$tokeninfo = M("User") -> where($where) -> getField("token");
						if ($token == $tokeninfo) 
						{
							return true;
						}
						else
						{
							return false;
						}
					}
		}
	}